<extend name="public@base5"/>
<block name="head">
	<link rel="stylesheet" href="__STATIC__/css/mall.css?v={$_static_version}"></link>
        <include file="theme/functions"/>        
</block>

<block name="main">
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li class="nav-item">
				<a class="nav-link" href="{:url('Store/subIndex',['type'=>$store_type])}">商品列表</a>
			</li>
			<li class="nav-item">
				<a class="nav-link active" href="{:url('Store/add',['type'=>$store_type])}">编辑商品</a>
			</li>
		</ul>
		<form method="post" class="js-ajax-form margin-top-20" action="admin/stores">
			<input type='hidden' id='item_id' name='id' value='{$id}'>
			<input type="hidden" name="store_type" value="{$store_type}">
                        <div class="row mb-3">
				<label for="input-item_name" class="col-sm-2 col-form-label text-sm-end"><span class="form-required">*</span>商品编号</label>
				<div class="col-md-6 col-sm-10">
					<input type="text" class="form-control" name="nid" value='{$id}'>
				</div>
			</div>
			<div class="row mb-3">
				<label for="input-item_name" class="col-sm-2 col-form-label text-sm-end"><span class="form-required">*</span>商品名称</label>
				<div class="col-md-6 col-sm-9">
                                    <input type="text" class="form-control" id="input-item_name" name="item_name" value='{$item_name}' oninput="change_name(this.value)"/>
                                    
				</div>
                                <div class="col-md-2 col-sm-1">
                                <label id="item_name_length"></label>
                                </div>
			</div>
			<div class="row mb-3">
				<label for="input-item_type" class="col-sm-2 col-form-label text-sm-end"><span class="form-required">*</span>商品类型</label>
				<div class="col-md-2 col-sm-2">
                                    <input type="text" class="form-control" id="input-item_type" name="item_type" value='{$item_type}' placeholder="商品类型" >
				</div>
				<div class="col-md-8 col-sm-8">
                                    <foreach name="item_types" item="vo">
                                            <a class="btn btn-primary js-select-type" href="#">{$vo.item_type}</a>
                                    </foreach>
				</div>
			</div>
                        <div class="row mb-3">
                        <if condition="$booth_type==1">
				<label for="input-item_name" class="col-sm-2 col-form-label text-sm-end"><span class="form-required">*</span>价格</label>
				<div class="col-md-2 col-sm-10">
					<input type="number" class="form-control" id="input-item_name" name="item_price" value='{$item_price}'/>
				</div>
			
                        </if>
                        
				<label for="input-item_order" class="col-sm-2 col-form-label text-sm-end"><span class="form-required">*</span>排序</label>
				<div class="col-md-2 col-sm-10">
					<input type="number" class="form-control" id="input-item_order" name="item_order" value="{$item_order|default=1000}">
				</div>
			</div>
			<div class="row mb-3">
				<label for="input-item_type" class="col-sm-2 col-form-label text-sm-end">标签</label>
				<div class="col-md-8 col-sm-8">
					<div id="tag_selected_container">
						<foreach name="tags" item="vo">
							<div class="btn btn-secondary tag-item" data-id="{$vo.id}">{$vo.tag_name}:{$vo.tag_value}
								<i class="fa fa-close"></i></div>
						</foreach>
					</div>
					<div id="tag_container"></div>
					<a class="btn btn-primary add-tag" data-type="{$booth_type}"><i class="fa fa-plus"></i></a>
				</div>
			</div>

			<div class="row mb-3">
				<label for="input-item_desc" class="col-sm-2 col-form-label text-sm-end"><span class="form-required">*</span>商品描述</label>
				<div class="col-md-8 col-sm-10">
					<input type="text" class="form-control" id="input-item_desc" name="item_desc" value='{$item_desc}'>
				</div>
			</div>
			
			
                        <div class="row mb-3">
				<label for="item_icon" class="col-sm-2 col-form-label text-sm-end"><span class="form-required">*</span>图标</label>
				<div class="col-md-8 col-sm-10">
                                        <php>  
                                            $img = $item_icon?cmf_get_image_preview_url($item_icon):'';
						$avatar_item = [];
						$avatar_item['item_icon']['value'] = $img;
						$avatar_item['item_icon']['type'] = "image2";
					</php>
					{:_parse_vars($avatar_item, 'item_icon')}
					<small class="text-muted">{:lang('UPLOAD_SINGLE_IMAGE_FORMAT_2MB')}</small>   
				</div>
			</div>
                        
                         <div class="row mb-3">
				<label for="item_icon" class="col-sm-2 col-form-label text-sm-end">视频</label>
				<div class="col-md-8 col-sm-10">
					<input type="hidden" name="video_url" id="item_video"
                                       value="{$item_video|default=''}">
                                <a class='btn btn-primary' href="javascript:uploadOne('上传视频','#item_video','video');">
                                    上传视频
                                </a>
                                        
                                <br>
                                
                                <if condition="!empty($video_url)">
                                    <a href='{:cmf_get_image_url($video_url)}'>预览视频</a>
                                </if>
                                <small class="text-muted">上传视频文件(MP4,Mov,Avi,Mpeg)</small>   
				</div>
			</div>
                        
                        <div class="row mb-3">
				<label for="model_url" class="col-sm-2 col-form-label text-sm-end">模型</label>
				<div class="col-md-8 col-sm-10">
					<input type="hidden" name="model_url" id="model_url"
                                       value="{$model_url|default=''}">
                                
                                <if condition="empty($model_url)">
                                    <a class='btn btn-primary' href="javascript:uploadOne('上传模型','#model_url');">
                                    上传模型
                                </a>
                                        <else />
                                        <a class='btn btn-primary' href="javascript:uploadOne('上传模型','#model_url');">
                                    替换模型
                                </a>
                                        <a class="btn btn-info" href='{:cmf_get_image_url($model_url)}'>下载模型</a>
                                        <a class="btn btn-danger js-ajax-delete" href="{:url('delete_model',['id'=>$id])}">删除模型</a>
                                </if>
                                <br/>
                                <small class="text-muted">上传3D模型(FBX,Obj,3DS)</small>   
				</div>
			</div>
                        
                        <div class="row mb-3">
				<label for="item_icon" class="col-sm-2 col-form-label text-sm-end"><span class="form-required">*</span>相册</label>
				<div class="col-md-8 col-sm-10 image_list">
                                    {:_parse_vars($item_images, 'item_images')}
                                    
				</div>
			</div>
			
			<div class="row mb-3">
                            <div class="offset-md-2 col-sm-10">
                                <button type="submit" class="btn btn-primary js-ajax-submit">
                                    <i class="fa fa-save fa-fw"></i> {:lang('SAVE')}
                                </button>
                                <a class="btn btn-danger js-dialog-btn" data-msg="确定不保存吗?" data-href="{:url('Store/subIndex',['type'=>$store_type])}">
                                    <i class="fa fa-save fa-fw"></i> 取消
                                </a>
                            </div>
			</div>
		</form>
	</div>
</block>

<block name="scripts">
	<script src="__STATIC__/js/mall.js"></script>
        <include file="theme/scripts"/>
        <script>
            function change_name(content){
                var len = content.length;
                var max = 30;
                if(len>=max){
                    content = content.substr(0,max);
                    $('#input-item_name').val(content);
                    len = max;
                }
                $('#item_name_length').text(len+"/"+max);
            }
        </script>
</block>
